package com.surekam.dma.web.dma.dms;

import java.util.List;
import org.apache.struts2.convention.annotation.Namespace;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;
import org.springside.modules.utils.web.struts2.Struts2Utils;
import com.surekam.dma.entity.dma.dms.DocuType;
import com.surekam.dma.service.ServiceException;
import com.surekam.dma.service.dma.dms.DocuTypeManager;
import com.surekam.dma.web.CrudActionSupport;

@Namespace("/docuType")
public class DocuTypeAction	extends CrudActionSupport<DocuType>{
	private static final long serialVersionUID = 1L;
	private DocuTypeManager docuTypeManager;
	private Long id;
	private DocuType entity;
	private Page<DocuType> page = new Page<DocuType>(8);
	public void setId(Long id) {
		this.id = id;
	}
	public DocuType getModel() {
		return entity;
	}
	@Override
	protected void prepareModel() throws Exception {
		if(id != null){
			entity=docuTypeManager.getDocuType(id);
		}else{
			entity=new DocuType();
		}
	}
	@Override
	public String list() throws Exception {
		List<PropertyFilter> filters = PropertyFilter.buildFromHttpRequest(Struts2Utils.getRequest());
		if(!page.isOrderBySetted()){
			page.setOrderBy("id");
			page.setOrder(Page.ASC);
		}
		page = docuTypeManager.searchDocuType(page, filters);
		return SUCCESS;
	}
	@Override
	public String input() throws Exception {
		return INPUT;
	}
	@Override
	public String save() throws Exception {
		docuTypeManager.saveDocuType(entity);
		addActionMessage("保存成功");
		return RELOAD;
	}
	@Override
	public String delete() throws Exception {
		try{
			docuTypeManager.deleteDocuType(id);
			addActionMessage("删除成功");
		}catch(ServiceException e){
			logger.error(e.getMessage(), e);
			addActionMessage("删除失败");
		}
		return RELOAD;
	}
	/**
	 * list页面显示分页列表.
	 */
	public Page<DocuType> getPage() {
		return page;
	}	
}
